/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __M2_SKIN_FILE_H__
#define __M2_SKIN_FILE_H__

#include "M2.h"
#include "FileBase.h"

namespace PQGameCore
{
	/*Define submesh and submesh textures?
	http://www.madx.dk/wowdev/wiki/index.php?title=M2/WotLK/.skin
	They are named like Modelname0x.skin,
	where Modelname is the same name as the model has and x is a digit from 0 to 3 representing each View / LOD
	*/
	class M2SkinFile
	{
	public:
		~M2SkinFile(void);

		M2SkinFile(PQEngine::FileBase *f);
		
		inline bool ok()
		{
			return _ok;
		}

		int getTexUnitsCount()
		{
			if(_header!=0){
				return _header->nTex;
			}else{
				return 0;
			}
		}

		int getSubMeshCount()
		{
			if(_header!=0){
				return _header->nSub;
			}else{
				return 0;
			}
		}


		M2TexUnit* getTexUnitPtr()
		{
			return _textUnits;
		}

		M2SubMesh* getSubMeshPtr()
		{
			return _subMeshes;
		}

		unsigned short *getIndicesPtr()
		{
			return _indices;
		}

		int getIndicesCount()
		{
			return _nIndices;
		}
	private:
		bool parse();
	private:
		PQEngine::FileBase* _file;
		char* _buf;
		bool _ok;
		
		M2SkinHeader *_header;
		M2SubMesh* _subMeshes;
		M2TexUnit* _textUnits;

		int _nIndices;//number of trangles
		unsigned short *_indices;
	};
}
#endif
